<template>
	<view class="goods-detail">
		<view class="goods-top">
			<view class="goods-logo-container">
				<img class="goods-logo" :src="detail.logo" />
			</view>
			<view class="goods-intro">
				<view class="goods-title">
					{{detail.name}}
				</view>
				<view class="goods-factory">
					{{detail.company}}
				</view>
			</view>
		</view>
		<view class="goods-main">
			<view class="goods-attr">
				<view class="label">主治疾病</view>
				<view class="content">{{detail.primary_disease}}</view>
			</view>
			<view class="goods-attr">
				<view class="label">注意事项</view>
				<view class="content">{{detail.announcements}}</view>
			</view>
			<view class="goods-attr">
				<view class="label">主要成分</view>
				<view class="content">{{detail.main_components}}</view>
			</view>
			<view class="goods-attr">
				<view class="label">用法用量</view>
				<view class="content">{{detail.usage}}</view>
			</view>

		</view>
		<view class="tips" :class="{'success':isAffected === false,'danger':isAffected === true}">
			<view class="label">检测结果</view>
			<view class="content">
				<template v-if="isAffected">
					<TnIcon name="close-fill" custom-class="icon-checked" />

					小光提醒对毛发检测有影响：<b v-for="item in affects" class="affected">{{item}}</b> 会阳性
				</template>
				<template v-else>
					<TnIcon name="success" custom-class="icon-checked" /> 小光提醒对毛发检测没有影响
				</template>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { ref, reactive, getCurrentInstance } from 'vue'
	import { onLoad } from "@dcloudio/uni-app"
	import { getComponent } from '@/utils/api';
	let detail : any = reactive({})

	// 是否有影响
	const isAffected = ref(false);
	const affects = ref();

	onLoad((option) => {
		Object.assign(detail, JSON.parse(option?.info))
		uni.setNavigationBarTitle({
			title: detail?.name
		});
		checkComponent();


		const { proxy } : any = getCurrentInstance()
		const newMethod = proxy.$wxShare;
		var url = window.location.protocol + "//" + window.location.host;
		const pages = getCurrentPages();
		const link = url + "/#/" + pages[pages.length - 1].route
		newMethod("", "", link)
	})

	// 检测成分
	const checkComponent = async () => {
		const { data } = await getComponent(detail.name, detail.main_components);

		isAffected.value = data?.length > 0;
		affects.value = data;
	}
</script>

<style lang="scss" scoped>
	.goods-detail {
		background: #fff;
		padding: 12rpx 28rpx;

		.goods-top {
			align-items: center;
			border: 2rpx solid #f5f5f5;
			border-radius: 12rpx;
			display: flex;
			flex-wrap: wrap;
			padding: 24rpx 0;
			width: 696rpx;

			.goods-logo-container {
				margin-left: 24rpx;

				.goods-logo {
					border: 1px solid #f0f0f0;
					border-radius: 8rpx;
					height: 200rpx;
					width: 200rpx;
				}
			}


			.goods-intro {
				height: 200rpx;
				margin-left: 20rpx;
				width: 428rpx;

				.goods-title {
					color: #191919;
					font-size: 32rpx;
					line-height: 44rpx;
				}

				.goods-factory {
					color: #333333;
					font-size: 20rpx;
					height: 28rpx;
					line-height: 28rpx;
					margin-top: 24rpx;
				}
			}
		}
	}

	.goods-main {
		color: #333;
		font-family: PingFangSC-Regular, PingFang SC;
		font-size: 24rpx;
		font-weight: 400;

		.goods-attr {
			.label {
				color: #000;
				font-size: 32rpx;
				margin-bottom: 24rpx;
			}

			margin-left: 24rpx;
			margin-top: 24rpx;
			border-bottom: 1px dotted #999999;
			padding-bottom: 30rpx;

			&:last-child {
				border-bottom: none;
			}
		}
	}

	.tips {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;

		.label {
			font-size: 36rpx;
			font-weight: 700;
			line-height: 35rpx;
			padding: 21rpx 0 19rpx;
			text-align: center;
			border-bottom: 4rpx solid #383838;
		}

		.content {
			padding: 30rpx 80rpx 100rpx;
			line-height: 35rpx;
			font-size: 24rpx;
		}
	}

	.success {
		background-color: #4FE3B7;
	}

	.danger {
		background-color: #FF5733;
	}

	.affected {
		font-size: 36rpx;
	}

	.icon-checked {
		font-size: 36rpx;
		position: relative;
		top: 4rpx
	}
</style>